<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:include="include :: header"></head>
<body class="hold-transition skin-blue sidebar-mini">
<!--文件描述修改模态框-->
<div class="modal fade" id="modal-updateExplain">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">驳回</h4>
            </div>
            <div class="modal-body">
                <form id="editFormExplain" class="form-horizontal" role="form">
                    <input id="idFile" type="hidden" name="id">
                    <div class="form-group">
                        <label for="rejectReason" class="col-sm-2 control-label no-padding-right">驳回原因</label>
                        <div class="col-sm-10">
                            <textarea class="form-control" id="rejectReason" name="rejectReason" rows="3"></textarea>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-info" id="btn-updateExp">确定</button>
            </div>
        </div>
    </div>
</div>
<section class="content-header">
    <h1>安装派工单审核</h1>
</section>
<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="box-header">
                    <form id="queryForm" onsubmit="return false;">
                        <div class="row">
                            <div class="form-inline">
                                <div class="form-group">
                                    <label for="query-proCode">生产令号</label>
                                    <input id="query-proCode" type="text" name="proCode" class="form-control"
                                           placeholder="请输入生产令号">
                                </div>
                                <div class="form-group">
                                    <label for="query-proName">项目名称</label>
                                    <input id="query-proName" type="text" name="proName" class="form-control"
                                           placeholder="请输入项目名称">
                                </div>
                                <div class="form-group">
                                    <label for="query-installPlace">安装地点</label>
                                    <input id="query-installPlace" type="text" name="installPlace" class="form-control"
                                           placeholder="请输入安装地点">
                                </div>
                                <div class="form-group">
                                    <label for="query-customer">需方</label>
                                    <input id="query-customer" type="text" name="customer" class="form-control"
                                           placeholder="请输入需方">
                                </div>
                                <!--<div class="form-group">-->
                                    <!--<label for="query-isDebugging">是否需要调试</label>-->
                                    <!--<select id="query-isDebugging" class="form-control" name="isDebugging">-->
                                        <!--<option value="" selected>全部</option>-->
                                        <!--<option value="1">需要</option>-->
                                        <!--<option value="2">不需要</option>-->
                                    <!--</select>-->
                                <!--</div>-->
                                <div class="form-group">
                                    <label for="query-debuggingStatu">状态</label>
                                    <select id="query-debuggingStatu" class="form-control" name="subStatus">
                                        <option value="" >全部</option>
                                        <option value="2" selected>待审核</option>
                                        <!--<option value="1">未提交</option>-->
                                        <option value="3">已审核</option>
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label for="query-startTime">创建日期</label>
                                    <input id="query-startTime" type="text" class="form-control datepicker"
                                           name="startTime"
                                           readonly="readonly"/>
                                    <label for="query-endTime"> 至 </label>
                                    <input id="query-endTime" type="text" class="form-control datepicker" name="endTime"
                                           readonly="readonly"/>
                                </div>
                                <button type="button" class="btn btn-success" id="btn-search"
                                        onclick="js.table.search(table)">
                                    <span class="Bold">搜索</span>
                                </button>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="box-body">
                    <table id="bootstrap-table"></table>
                </div>
            </div>
        </div>
    </div>
</section>
<div th:include="include :: footer"></div>
<script th:inline="javascript">

    let table;
    var statusName = ["", "未提交", "待审核", "已审核"];
    var classType = ["label-primary", " label-default", " label-warning", " label-success"];

    $(function () {

        table = js.table.init({
            url: ctx + "create/dispatching/submitList",
            showExport: false,
            columns: [
                {
                    title: '序号', width: '50',
                    formatter: function (value, row, index) {
                        return index + 1;
                    }
                },
                {title: "生产令号", field: 'proCode'},
                {title: "订单数量", field: 'prodNum', width: '50'},
                {title: "项目名称", field: 'proName', width: '220'},
                {title: "安装地点", field: 'installPlace', width: '220'},
                {title: "需方", field: 'customer', width: '220'},
                {title: "驳回原因", field: 'rejectReason'},
                {title: "创建日期", field: 'authorTime', width: '100'},
                {
                    title: "状态", field: 'subStatus', width: '80',
                    formatter: function (value) {
                        return '<span class="badge' + classType[value] + '">' + statusName[value] + '</span>';
                    }
                },
                {
                    title: "操作",
                    formatter: function (value, row) {
                        let actions = [];
                        actions.push('<a class="btn btn-info btn-xs" target="_blank"  href="' +ctx + 'create/dispatching/listDetailSelect/' + row.id + '" > 查看</a>');
                        if (row.subStatus==2){
                            actions.push('<a class="btn btn-success btn-xs" shiro:hasPermission="conInstall:creaud:check"  onclick="examine(' + row.id + ')"> 审核</a> ');
                            actions.push('<a class="btn btn-danger btn-xs" shiro:hasPermission="conInstall:creaud:check" onclick="openReject('  + js.jsonStringify(row) + ')" > 驳回</a> ');
                        }
                        if (row.subStatus==3){
                            actions.push('<a class="btn btn-danger btn-xs" shiro:hasPermission="conInstall:creaud:check" onclick="openReject('  + js.jsonStringify(row) + ')" > 驳回</a> ');
                        }
                        return actions.join('');
                    }
                }
            ]
        });
    });
    /** 提交数据待审核 */
    function examine(id) {
        js.modal.confirm("确定要审核吗？", function () {
            js.post({
                url: ctx + "create/dispatching/examine",
                data: {id: id},
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        js.modal.success(result.msg);
                        js.table.refresh(table);
                    } else {
                        js.modal.warning(result.msg);
                    }
                }
            })
        })
    }
    /** 打开编辑模态框 */
    function openReject(result) {
        $("#idFile").val(result.id);
        $("#rejectReason").val(result.rejectReason);
        js.modal.open("modal-updateExplain");
    }
    /** 修改描述） */
    $("#btn-updateExp").click(function () {
        js.validSubmit({
            formId: "editFormExplain",
            url: ctx + "create/dispatching/reject",
            data: new FormData($("#editFormExplain")[0]),
            success: function (result) {
                if (result.type === web_status.SUCCESS) {
                    js.modal.success(result.msg);
                    js.table.refresh(table);
                    js.modal.hide("modal-updateExplain");
                } else {
                    js.modal.warning(result.msg);
                }
            }
        });
    });
</script>
</body>
</html>
